package edu.gyc.game;

import java.util.ArrayList;
public class Ship {
    private String name;
    //每一艘战舰在棋盘上的坐标，坐标是连续的三个字符串，比如11,12,13,既然坐标是固定的三个元素，为什么不用数组存储？
    private ArrayList<String> locations=new ArrayList<String>();
    public Ship(String name) {
        this.name = name;
    }
    public ArrayList<String> getLocations() {
        return locations;
    }
    public String getName() {
        return name;
    }
    public void setLocations(ArrayList<String> locations) {
        this.locations = locations;
    }

    public void setName(String name) {
        this.name = name;
    }
    //战舰根据参数userInput判断自己是否被击中或击沉，通过return返回检查结果
    public String checkHit(String userInput){
        String result="no";
        if(locations.indexOf(userInput)>=0){
            result="hit";
            locations.remove(userInput);
        }
        if(locations.isEmpty())
            result="sink";
        return result;
    }
    public String toString(){

        return name+" :"+locations.toString();
    }
}
